var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    accountName:"",
    bankName:"",
    bankNo:"",
    bankDeposit:"",
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.loadings();
  },

  //获取医生银行个人信息
  loadings: function() {
    var that = this;
    wx.request({
      url: app.globalData.baseUrl + 'doctor/doctor/doctorBankInfo',
      data: {

      },
      header: {
        'sign': app.globalData.sign,
        'token': app.globalData.token,
        'content-type': 'application/x-www-form-urlencoded;charset=utf-8',
      },
      method: 'POST',
      success(res) {
        console.log('医生银行账户信息:', res.data);
        console.log('医生银行账户信息:', res.data.data[0]);
        that.setData({
          accountName: res.data.data[0].accountName,
          bankName: res.data.data[0].bankName,
          bankNo: res.data.data[0].bankNo,
          bankDeposit: res.data.data[0].bankDeposit,
        })
      }
    })
  },
  //保存
  nextstep: function() {
    var accountName = this.data.accountName;
    var bankName = this.data.bankName;
    var bankNo = this.data.bankNo;
    var bankDeposit = this.data.bankDeposit;
    console.log('accountName', accountName);
    console.log('bankName', bankName);
    console.log('bankNo', bankNo);
    console.log('bankDeposit', bankDeposit);
    if (accountName == '') {
      wx.showToast({
        title: '请添加您的账户名称',
        icon: 'none',
        duration: 1000
      })
      return false;
    }
    if (bankName == "") {
      wx.showToast({
        title: '请输入您的银行名称',
        icon: 'none',
        duration: 1000
      })
      return false;
    }
    if (bankNo == "") {
      wx.showToast({
        title: '请输入您的银行账户',
        icon: 'none',
        duration: 1000
      })
      return false;
    }

    if (bankDeposit == "") {
      wx.showToast({
        title: '请输入您的开户行地址',
        icon: 'none',
        duration: 1000
      })
      return false;
    }
    wx.request({
      url: app.globalData.baseUrl + 'doctor/doctor/editBankInfo',
      data: {
        accountName: accountName,
        bankName: bankName,
        bankNo: bankNo,
        bankDeposit: bankDeposit,
      },
      header: {
        'sign': app.globalData.sign,
        'token': app.globalData.token,
        'content-type': 'application/x-www-form-urlencoded;charset=utf-8',
      },
      method: 'POST',
      success(res) {
        console.log('完善医生银行账户:', res)
        if (res.statusCode == 200) {
          wx.showToast({
            title: res.data.message,
            icon: 'success',
            duration: 2000
          })
          setTimeout(function() {
            wx.reLaunch({
              url: '../doctor-my/doctor-my',
            })
          }, 2000)
        }
      }
    })
  },
  getnameValue: function(e) {
    // console.log("name", e.detail.value)
    this.setData({
      accountName: e.detail.value
    })
  },
  getbanklValue: function(e) {
    // console.log("bank", e.detail.value)
    this.setData({
      bankName: e.detail.value
    })
  },
  getmunberValue: function(e) {
    // console.log("number", e.detail.value)
    this.setData({
      bankNo: e.detail.value
    })
  },
  getaddressValue: function(e) {
    // console.log("number", e.detail.value)
    this.setData({
      bankDeposit: e.detail.value
    })
  },


  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})